var projectName = $("#projectName").val();
var cdnAddress = $("#cdnAddress").val();
var url = "";
var lang1 = "";
var lang2 = "";

var test = window.location.search;
if(test == "" || test==null || test == "?lang=zh_CN") {
	url = projectName+"/OffLanguageZhCnAdmin/queryAll";
	lang(url)
//	url = "http://www.localhost:9090/hero/officialAdmin/officialPage.html?lang=en_US";
	lang1 = "中文";
	lang2 = "English";
}else if(test == "?lang=en_US"){
	url = projectName+"/OffLanguageEnUsAdmin/queryAll";
	lang(url)
	//url = "http://www.localhost:9090/hero/officialAdmin/officialPage.html?lang=zh_CN";
	lang1 = "English";
	lang2 = "中文";
	
}else {
	url = projectName+"/OffLanguageZhCnAdmin/queryAll";
	lang(url)
	//url = "http://www.localhost:9090/hero/officialAdmin/officialPage.html?lang=en_US";
	lang1 = "中文";
	lang2 = "English";
}


function lang() {
	readData("MENU_1",url);
	readData("MENU_2",url);
	readData("MENU_3",url);
	readData("MENU_4",url);
	readData("MENU_5",url);
	readData("MENU_6",url);
	//readData("MENU_7",url);
	readData("MENU_8",url);
}


/**
 * 联系我们
 * @param result
 * @returns
 */
function menu_8(result) {
	for(var i=0; i<result.length; i++){	
		if(result[i].grade == 1){
   			$("#contact div.heading-left-light").append("<h2>"+result[i].title+"</h2><p>"+result[i].content+"</p>");
   		}else if(result[i].grade == 2){
   			switch(result[i].anchor){
       			case "userName" :$("#userName").attr("placeholder",result[i].title);break;
       			case "theme" :$("#theme").attr("placeholder",result[i].title);break;
       			case "email" :$("#email").attr("placeholder",result[i].title);break;	
       			case "phone" :$("#phone").attr("placeholder",result[i].title);break;
       			case "comment" :$("#comment").attr("placeholder",result[i].title);break;
       			default:break;
   			}
   		}else if(result[i].grade == 3){
   			$("#contacttxt-send").text(result[i].title);
   		}
	}
}

/**
 * 产品价格
 * @param result
 * @returns
 */
function menu_7(result) {
	var count = 0;
	for(var i=0; i<result.length; i++){	
		if(result[i].grade == 1) { 
        	$("#pricing div.heading").append("<h2>"+result[i].title+" <strong>"+result[i].content+"</strong></h2><P>"+result[i].contentD+"</P>")
		}else if(result[i].grade == 2 ) {
			if(count < 3){
				var MENU = "";
				MENU += "<h4>"+result[i].title+"</h4><span>" +result[i].content+"</span>";
				MENU += "<ul class=pricing-features>";
				var array = result[i].contentD.split(",");
				for(var j = 0; j < array.length; j++) {
					MENU += "<li>"+array[j]+"</li>";
				}
				MENU += "</ul>";
				$("#col-md-4_" + count).append(MENU)
				count++;
       		}
		}else if(result[i].grade == 3) {
			for(var j = 0; j < 3 ; j++) {
				if(j == 1) {
					$("#col-md-4_" + j).append("<button type=button class=btn-brd-white>"+result[i].title+"</button>")
				}else{
					$("#col-md-4_" + j).append("<button type=button class=btn-brd-primary>"+result[i].title+"</button>")
				}
				
			}
		}
	}
}

var menuresult;
/**
 * 成功案例
 * @param result
 * @returns
 */
function menu_6(result) {
	menuresult = result;
	var MENU_6 = "";
	for(var i=0; i<result.length; i++){	
		if(result[i].grade == 1) {
			 $("#portfolio div.heading").append("<h2>"+result[i].title+" "+result[i].content+"</h2>")
		 }else if(result[i].grade == 2) {
			 if(result[i].picture == null && result[i].anchor != null){
				MENU_6 += "<div data-filter="+result[i].anchor+" class='cbp-filter-item-active cbp-filter-item' style='text-decoration:none;' onclick='checkText(6)'>"+result[i].title+"</div>";
			 }else if(result[i].picture != null){
				MENU_6 += "<div data-filter="+result[i].anchor+" class='cbp-filter-item' ><a href='javascript:void(0)' style='text-decoration:none;' onclick='checkText("+i+")'>"+result[i].title+"</a></div>";
				if (result[i].anchor == '.ecommerce') {
					$("#electronicSrc").attr('src',projectName+"/"+ result[i].pictureUrl);
				}else if (result[i].anchor == '.admin') {
						$("#subjectSrc").attr('src',projectName+"/"+ result[i].pictureUrl);
				}else if (result[i].anchor == '.corporate') {
						$("#corporateSrc").attr('src',projectName+"/"+ result[i].pictureUrl);
				}else if (result[i].anchor == '.retail') {
						$("#retailSrc").attr('src',projectName+"/"+ result[i].pictureUrl);
				}
				}else if(result[i].picture == null && result[i].anchor == null){
					var MENU = "";
					MENU += "<h2><strong>"+result[i].title+"</strong><br>" +result[i].content+"</h2>" ;
					MENU += "<p>"+result[i].contentD+"</p><br>";
					$("#portfolio div.heading-left").append(MENU);
				 } 
			 }
		 }
		/*else if(result[i].grade == 3 ){
			 $("#portfolio div.heading-left").append("<a href=# class=btn-brd-primary>"+result[i].title+"</a>");
		 }*/
	$("#filters-container").append(MENU_6);
}

function checkText(val){
	$("#portfolio div.heading-left").empty();
	var MENU = "";
	MENU += "<h2><strong>"+menuresult[val].title+"</strong><br>" +menuresult[val].content+"</h2>" ;
	MENU += "<p>"+menuresult[val].contentD+"</p><br>";
	$("#portfolio div.heading-left").append(MENU);
	/*if (menuresult[val].anchor == '.corporate') {
		$("#corporateSrc").style.top="-320px";
	}else if (menuresult[val].anchor == '.retail') {
		$("#retailSrc").style.top="-320px";
	}*/
}
/**
 * 模块五: 合作伙伴
 * @param result
 * @returns
 */
function menu_5(result) {
	for(var i=0; i<result.length; i++){	
		if(result[i].grade == 1){
			$("#clients div.heading-blue").append("<h2>"+result[i].title+"</h2><p>"+result[i].content+"</p>"); 
		}else if(result[i].grade == 2) {
			
		}
	}
}


var count1 = 0;
/**
 * 模块四: 开发团队
 * @param result 从数据库读取的结果
 * @returns
 */
function menu_4(result) {
	var menuMember = "";
	var menuTechnology = "";
	for(var i=0; i<result.length; i++){	
		if(result[i].grade == 1){
	        $("#team div.heading-light").append("<h2>"+result[i].title+"</h2>");
		 }else if(result[i].picture != null && result[i].picture != ""){
			 menuMember += menu_4_Member(result,i)
		 }else {
			menuTechnology += menu_4_Technology(result,i)
		 }
	}
	$("#team div.col-md-8").append(menuMember)
	$("#team div.team-about").append(menuTechnology)
}

/**
 * 模块四: 开发团队人员模块
 * @param result
 * @param i
 * @returns
 */
function menu_4_Member(result,i) {
	var menu = "";
	if(count1 == 0 || count1/3 == 0){
		menu += "<div class=row>";
	}
	menu += "<div class=col-sm-4><div class=team-members><div class=team-avatar>";
	menu += "<img class=img-responsive src="+ projectName + "/" + result[i].pictureUrl +" alt=''>";
	menu += "</div><div class=team-desc><div class=team-details>";
	menu += "<h4>"+result[i].title+"</h4><span>"+result[i].content+"</span></div>";
	menu += "<ul class=team-socials><li><a href=#><i class=fa fa-facebook></i></a></li>";
	menu += "<li><a href=#><i class=fa fa-twitter></i></a></li></ul></div></div></div>";
	count1++;
	if(count1 / 3 == 0 || result[i+1].menuId == null) {
		menu += "</div>";
	}
	return menu;
}

/**
 * 模块四: 开发团队技术描述模块
 * @param result
 * @param i
 * @returns
 */
function menu_4_Technology(result,i,count) {
	var menu = "";
	menu += "<h3>"+result[i].title+"</h3>";
	menu += "<p>" + result[i].content + "</p>";
	menu += "<div class=margin-bottom-40></div>";
	return menu;
}

/**
 * 模块三: 产品特点
 * @param result 从数据库读取的结果
 * @returns
 */
function menu_3(result) {
	var count = 0;
	for(var i=0; i<result.length; i++){	
 		if(result[i].grade == 1){
			$("#features div.heading").append("<h2>"+result[i].title+"</h2>" + "<p>"+result[i].content+"</p>")
		}else if(result[i].grade == 2){
			var menu = "";
			menu += "<img src="+ projectName + "/" + result[i].pictureUrl +" alt=''>";
			menu += "<div class=features-in>";
			menu += "<h3><a href=#>"+result[i].title+"</a></h3>";
			menu += "<p>"+result[i].content+"</p>";
			menu += "</div>";
	       	if( count < 4){
	       		$("#features_" + count).append(menu);
	       		count++;
	       	}
		}else {
			$("#tfree").append("<a href=# class=btn-brd-danger>"+result[i].content+"</a>")
		}
	}
}

/**
 * 模块二: 关于我们
 * @param result 从数据库读取的结果
 * @returns
 */
function menu_2(result) {
	var menu = "";
	for(var i=0; i<result.length; i++){	
		menu += "<div class=col-sm-4>";
		menu += "<div class=services sm-margin-bottom-100>";
		menu += "<div class=services-wrap>";
		menu += "<div class=service-body>";
		menu += "<img src=" + projectName + "/" + result[i].pictureUrl + " alt=>";
		menu += "</div>";
		menu += "</div>";
		menu += "<h2>" + result[i].title + "</h2>";
		menu += "<p>"+result[i].content+"</p>";
		menu += "</div>";
		menu += "</div>";
	}
	$("#about_row").append(menu)
}

/**
 * 模块一: 官网导航栏和轮播图
 * @param result 从数据库读取的结果
 * @returns
 */
function menu_1(result) {
	var menu = "";
	for(var i=0; i<result.length; i++){	
		if(result[i].title != null) {
			if(result[i].seq == 1) {
				var home = "<li class=page-scroll active><a href="+result[i].anchor+">"+result[i].title+"</a></li>";
				home += menu;
				menu = home;
			}else{
				menu += "<li class=page-scroll><a href="+result[i].anchor+">"+result[i].title+"</a></li>";
   	  		}
		}
	}
//	menu += "<li class=internationalization onclick=displaySub(this) onmouseover=displaySubMenu(this) onmouseout=hideSubMenu(this)> ";
//	menu += "<a href=#>"+lang1+"</a>";
//	menu += "<ul><li style=padding: 0px; padding-top: 20px;><a href="+url+">";
//	menu += lang2 +"</a></li> </ul></li>";
	$("#menuUiDiv").append(menu)
}




/**
 * 从数据库读取数据
 * @param menuId 模块ID
 * @returns
 */
function readData(menuId,url) {
	$.ajax({
		type: "post",  async : true,   url:url,
		data: {menuId:menuId},  dataType: 'json',
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		success: function(result) {
			if(menuId != null){
				switch(menuId) {
					case "MENU_1":menu_1(result); break;
					case "MENU_2":menu_2(result); break;
					case "MENU_3":menu_3(result); break;
					case "MENU_4":menu_4(result); break;
					case "MENU_5":menu_5(result); break;
					case "MENU_6":menu_6(result); break;
					case "MENU_7":menu_7(result); break;
					case "MENU_8":menu_8(result); break;
				}
			}
		},
		error : function(errorMsg) {
			//请求失败时执行该函数
			alert("加载menu按钮失败!");
		}
	});
}


/**
 * 国际化按钮
 * @param li
 * @returns
 */		
function displaySubMenu(li) {
	var subMenu = li.getElementsByTagName("ul")[0];
	subMenu.style.display = "block";
}
function hideSubMenu(li) {
	var subMenu = li.getElementsByTagName("ul")[0];
	subMenu.style.display = "none";
}

function displaySub() {

	$('.navbar-nav li a').on("click", function(event) {
		$(".navbar-collapse.in").collapse('show');
	});
}


/**
 * sayToJod
 */
function sayToJod() {
	var phone = $("#phone").val();
	if (phone.length > 11) {
		alert("联系电话不能超过11位");
		return;
	}
	var userName = $("#userName").val();
	if (userName == null || userName.trim().length == 0) {
		mini.alert("用户名不能为空！");
		return;
	}
	
	json = {
			userName:$("#userName").val(),
			email:$("#email").val(),
			theme:$("#theme").val(),
			phone:phone,
			comment:$("#comment").val(),
	}
	$.ajax({
		type: "post",  async : true,
		url : projectName+"/OffMessageAdmin/saveOffMessage",
		dataType : 'json',
		data : json,
		success : function(data) {
			alert("你好"+$("#userName").val()+",留言信息保存成功！");
			$("#userName").val("");
			$("#email").val("");
			$("#theme").val("");
			$("#phone").val("");
			$("#comment").val("");
		},
		error : function(jqXHR, textStatus, errorThrown) {
			
		}
	});
}